package matrix;

public class rotate {
    // 是正方形
    public static void rotate(int[][] matrix) {
        int n=matrix.length;
        int circle=n/2;
        for(int i=0;i<circle;i++){
            //处理的个数
            for(int j=i;j<n-1-i;j++){
                //四个角  01 13 32 20
                //左上i j    右上 j   n-1-circle   右下 n-1-circle   n-1-j  左下  n-1-j  circle  
                // circle=0，i=0，j=1》  01   13   32   20
                // circle=0，i=0，j=2》  02   23  31   10
                int n1=matrix[i][j],n2=matrix[j][n-1-i],n3=matrix[n-1-i][n-1-j],n4=matrix[n-1-j][i];
                matrix[j][n-1-i]=n1;
                matrix[n-1-i][n-1-j]=n2;
                matrix[n-1-j][i]=n3;
                matrix[i][j]=n4;
            }
        }
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix.length; j++) {
                System.out.println(matrix[i][j]);
            }
            System.out.println("====================");
        }

    }
    public static void main(String[] args) {
        // int[][]matrix=new int[][]{{1,2,3},{4,5,6},{7,8,9}};
        // int[][]matrix=new int[][]{{5,1,9,11},{2,4,8,10},{13,3,6,7},{15,14,12,16}};
        int[][]matrix=new int[][]{{5}};
        rotate(matrix);
    }
}
